﻿using Easy.Common.Helper.JWT;
using System.ComponentModel.DataAnnotations;

namespace Easy.Services.Entities
{
    /// <summary>
    /// BaseEntity
    /// </summary>
    public abstract class BaseEntity
    {
        /// <summary>
        /// 主键标识
        /// </summary>
        [Key]
        public long Id { get; set; }
        /// <summary>
        /// 是否删除，0默认、1删除
        /// </summary>
        public bool? IsDelete { get; set; } = false;

        /// <summary>
        /// 创建者Id
        /// </summary>
        public long? CreaterId { get; set; } = 0;
        public string CreaterName { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreaterDate { get; set; } = DateTime.Now;
        /// <summary>
        /// 编辑者Id
        /// </summary>
        public long? EditId { get; set; }
        /// <summary>
        /// 编辑时间
        /// </summary>
        public DateTime? EditDate { get; set; }

        public string EditName { get; set; }

        public void SetModelBase(TokenModelJwt tokenModel, bool isInit = false)
        {
            DateTime dateTime = DateTime.Now;
            if (isInit)
            {
                this.CreaterDate = dateTime;
                this.CreaterId = tokenModel.Id;
                this.CreaterName = tokenModel.UserName;
            }
            this.EditDate = dateTime;
            this.EditId = tokenModel.Id;
            this.EditName = tokenModel.UserName;

        }

        public void SetDelete()
        {
            this.IsDelete = true;
        }
        
    }
}
